<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/jsp/inc/header.jsp" %>
<c:set var="title" value="手表信息"/>
<c:set var="rootpath" value="${CONTEXT_PATH}/admin/product/watch/"/>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link href="${STATIC_HOST}/css/ligerui.css" rel="stylesheet" type="text/css"/>
	<link href="${STATIC_HOST}/css/common.css" rel="stylesheet" type="text/css" />

	<script src="${STATIC_HOST}/js/jquery/jquery-1.7.2.min.js" type="text/javascript" ></script>    <!--兼容性问题--->
	<script src="${STATIC_HOST}/js/ligerUI/ligerui.min.js" type="text/javascript"></script>
	<script src="${STATIC_HOST}/js/json/json2.js" type="text/javascript"></script>
	<script src="${STATIC_HOST}/js/LG.js" type="text/javascript"></script>
	<script src="${STATIC_HOST}/js/ckeditor/ckeditor.js" type="text/javascript"></script>
	<script src="${STATIC_HOST}/js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <title>${title}管理</title>
</head>
<body>
<form:form commandName="watch" class="l-form" id="mainform" name="mainform" method="post" action="${rootpath}/save.do">
<div class="pnl J_LigerForm">
	<div class="pnl-hd">
		<div class="hd-tit"><span>当前位置: 宇宙CMS&gt; <c:if test="${watch.id>0}"><a href="${rootpath}/list.do"/>${title}管理</a></c:if>&gt; ${watch.id==0 ? '新建' : '更新'}${title}</span></div>
		<div class="hd-bar">
			<input value="xxxxx" type="button" class="l-button" onClick="">
			<input value="xxxxx" type="button" class="l-button" onClick="">
		</div>
	</div>

	<div class="pnl-bd">
		<div id="errorLabelContainer"> <form:errors path="*"/>${error.param.wrong}</div>
		<input type="hidden" name="id" id="id" value="${watch.id}"/>
		<!--=============================基本信息==========================-->
		<fieldset class="field">
			<legend class="toggleBar">基本信息</legend>
			<div class="field-bd">
				<table class="tblWrap">
					<c:if test="${watch.id>0}">
						<tr>
							<th>手表ID：</th>
							<td>${watch.id}</td>
							<th>状态：</th>
							<td><c:if test="${watch.status==0}">无 效</c:if><c:if test="${watch.status==1}">有 效</c:if></td>
							<th>创建时间：</th>
							<td><fmt:formatDate value="${watch.createTime}" pattern="yyyy-MM-dd HH:mm" /></td>
							<th>修改时间：</th>
							<td><fmt:formatDate value="${watch.modifyTime}" pattern="yyyy-MM-dd HH:mm" /></td>
						</tr>
					</c:if>
				</table>
				<table class="tblWrap">
					<tr>
						<th>手表名称：</th>
						<td><input type="text" id="name" maxlength="50" name="name" ligerui="width:300" value="${not empty watch.name ? watch.name.replaceAll('\"', '&quot;') : ''}" validate="{required:true,minlength:0,maxlength:100}"/></td>
						<th><span class="required"></span>排 序：</th>
						<td><input type="text" name="sortNum" id="sortNum" value="${not empty watch.sortNum ? watch.sortNum : '0'}" ligerui="width:100"/></td>
					</tr>
					<tr>
						<th><span class="required"></span>简 称：</th>
						<td>
							<input type="text" name="nameShort" id="nameShort" value="${watch.nameShort}" ligerui="width:300"/>
						</td>
					</tr>
					<tr>
						<th><span class="required"></span>首 图：</th>
						<td>
							<input type="text" name="firstPicUrl" id="firstPicUrl" value="${watch.firstPicUrl}" ligerui="width:300"/>
						</td>
						<td>
							<img src="http://static.21cnimg.com/img/icons/silkicons/add.png" title="添加" alt="添加" style="cursor: pointer;"
								 onclick="f_select({'selectType':'/jsp/admin/resource/picture/uploads.jsp?multi=0&noConfirm=1','dialogWidth':'700','dialogHeight':'500','callback':'setFirstPicUrl'})"/>
						</td>
					</tr>
				</table>
				<table class="tblWrap">
					<tr>
						<th><span class="required"></span>品 牌：</th>
						<td>
							<input type="text" name="brandName" id="brandName" value="${watch.brandName}" ligerui="disabled:true" ltype="text"/>
							<input value="ID" type="button" class="l-button sChooBTN showId">
							<input type="text" class="idValue" ligerui="width:100" name="brandId" id="brandId" value="${watch.brandId==0?'':watch.brandId}"/>
							<input value="选择品牌" type="button" class="l-button ellipsis" style="min-width:80px;" onclick="f_select({'targetId':'parentId','selectType':'/admin/product/cate','callback':'callbackBrand','customParam':'&eqTypeId=5'})">
						</td>
					</tr>
					<tr>
						<th><span class="required"></span>性 别：</th>
						<td id="othersFiled">
							<span class="quickSearch <c:if test="${watch.sex==0}">point</c:if>" id="sex_0" value="0" onclick="setDefaultValue(0)">不限</span>|
							<span class="quickSearch <c:if test="${watch.sex==1}">point</c:if>" id="sex_1" value="1" onclick="setDefaultValue(1)">男</span>|
							<span class="quickSearch <c:if test="${watch.sex==2}">point</c:if>" id="sex_2" value="2" onclick="setDefaultValue(2)">女</span>|
							<input type="hidden" name="sex" id="sex" value="${watch.sex}">
						</td>
					</tr>
				</table>
			</div>
		</fieldset>


		<fieldset class="field">
			<legend class="toggleBar">手表图片
				<img src="http://static.21cnimg.com/img/icons/silkicons/add.png" title="添加" alt="添加" style="cursor: pointer;"
					 onclick="f_select({'targetId':'','selectType':'/jsp/admin/resource/picture/uploads.jsp?multi=1&noConfirm=1','dialogWidth':'700','dialogHeight':'500','callback':'setThumbPicUrl'})"/>
			</legend>
			<div class="field-bd">
				<table class="tblWrap">
					<c:if test="${empty watch.watchPictureList}">
						<tr id="thumbImgBox"></tr>
					</c:if>
					<c:if test="${!empty watch.watchPictureList}">
						<tr id="thumbImgBox">
							<c:forEach var="thumbPicture" items="${watch.watchPictureList}" varStatus="var">
								<td style="padding-right: 10px;">
									<img src="${thumbPicture.picUrl}"  width="120" height="90" alt="" title="" />
									<p>
										<input type="checkbox" name="thumbPicUrl" value="${thumbPicture.picUrl}" checked="checked"/>
									</p>
								</td>
							</c:forEach>
						</tr>
					</c:if>
				</table>
			</div>
		</fieldset>

		<fieldset class="field">
			<legend class="toggleBar">基本属性</legend>
			<div class="field-bd">
				<table class="tblWrap">
					<c:forEach var="obj" items="${propertyList}" varStatus="idx">
						<c:if test="${idx.index%4==0}">
							<tr>
						</c:if>
						<!--属性 start-->
						<th>${obj.name}：</th>
						<c:if test="${watch.id>0}">
							<td><input type="text" id="property_${obj.id}" name="property_${obj.id}" value="${propertyMap.get(obj.id)}"/></td>
						</c:if>

						<c:if test="${watch.id<=0}">
							<td><input type="text" id="property_${obj.id}" name="property_${obj.id}" value="${obj.defaultValue}"/></td>
						</c:if>
						<!--属性 end-->
						<c:if test="${idx.index%4==3}">
							</tr>
						</c:if>
					</c:forEach>
				</table>
			</div>
		</fieldset>

		<!-- 业务信息 start -->
		<fieldset class="field">
			<legend class="toggleBar">业务信息</legend>
			<div class="field-bd">
				<table class="tblWrap">
					<tr>
						<th><span class="required">*</span>二手价：</th>
						<td><input type="text" name="secondPrice" id="secondPrice" ltype='text' value="${watch.secondPrice}"/>（元）</td>
						<th><span class="required">*</span>市场价：</th>
						<td><input type="text" name="marketPrice" id="marketPrice" ltype='text' value="${watch.marketPrice}"/>（元）</td>
					</tr>
				</table>
			</div>
		</fieldset>
		<!-- 业务信息 end -->

		<fieldset class="field">
			<legend class="toggleBar">详细介绍</legend>
			<div class="field-bd">
				<table class="tblWrap" style="width:100%">
					<tr>
						<td><textarea id="J_CKEditor" name="details" rows="10" cols="80">${watch.details}</textarea></td>
					</tr>
					<tr>
						<td colspan="2">
							<table class="tblWrap">
								<tr>
									<td style="display:none;"><input type="checkbox" checked="true" name="localPic" id="localPic">远程图片本地化</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>
		</fieldset>
	</div>

	<div class="pnl-ft">
		<c:if test="${empty showType}">
			<input value="提交" type="button" class="l-button" onClick="javascript:submitForm();">
			<input value="取消" type="button" class="l-button" onClick="javascript:top.tab.removeTabItem(top.tab.getSelectedTabItemID());" >
		</c:if>
		<c:if test="${not empty showType}"> <input value="返回" type="button" class="l-button" onClick="javascript:history.back();" ></c:if>
	</div>
</div>
</form:form>
<div style="display:none;"><iframe src="${STATIC_HOST}/jsp/admin/resource/picture/imgFetch.jsp?status=1" id="imgFetchIframeRegion"></iframe></div>

<script type="text/javascript" >
	var editor = CKEDITOR.replace('J_CKEditor', {});

	var mainform = $("#mainform");
	mainform.ligerForm();

	commonFunction();
	attributeFieldSet();

	function submitForm(){
		document.mainform.submit();
	}

	function setThumbPicUrl(jsonData) {
		var data= jQuery.parseJSON(jsonData);
		var html = "";
		for(var i=0 ; i< data.length; i++){
			var title = data[i].title;
			var src = data[i].url;
			src = src.replace("/o/","/s/");
			html = html+'<td style="padding: 20px;">'+
					'<img width="120" height="90" title="'+title+'" alt="'+title+'" src="'+src+'">'+
					'<p><input type="checkbox" value="'+src+'" name="thumbPicUrl" id="thumbPicUrl"></p>'+
					'</td>';
		}
		jQuery("#thumbImgBox").append(html);
	}

	function setDefaultValue(id){
		jQuery("#sex_"+id).addClass("point");
		jQuery("#sex_"+id).siblings().removeClass("point");
		jQuery("#sex").val(id);
	}

	function commonFunction() {
		jQuery(".idValue",jQuery(".showId").parent()).parent().hide();
		jQuery(".showId").bind("click",function(){
			jQuery(".idValue",jQuery(this).parent()).parent().toggle();
		});
	}

	function attributeFieldSet(){			//设置填写栏目、区块ID后，获取名称处理方法
		jQuery("#brandId").focusout(function(){
			var brandId= jQuery("#brandId").val();
			brandId= brandId.split(/[,，]/gi);
			$.ajax({
				url: '/admin/product/cate/search.do?select=1&typeId=5&ids='+brandId[0],
				dataType: 'json',
				success: function(data) {
					if(data[brandId[0]]!== "" && data[brandId[0]]!==undefined){
						jQuery("#brandId").val(brandId[0]);
						jQuery("#brandName").val(data[brandId[0]]);
					}
					else{
						jQuery("#brandId").val("");
						jQuery("#brandName").val("");
					}
				}
			});
		});
	}

	function callbackBrand(jsonData){
		var result=  jQuery.parseJSON(jsonData);
		jQuery("#brandId").val(result[0].id);
		jQuery("#brandName").val(result[0].name);
	}

	function setFirstPicUrl(jsonData) {
		var data= jQuery.parseJSON(jsonData);
		var html = "";
		for(var i=0 ; i< data.length; i++){
			var title = data[i].title;
			var src = data[i].url;
			jQuery("#firstPicUrl").val(src);
		}
	}
</script>
<div id="scrolltop">返回顶部</div>
<%@ include file="/jsp/inc/footer.jsp"%>
</body>
</html>